package JavaSE.SETest.No01;

public class AddOne {
    static int[] list = {9, 9, 9};
    static int length = list.length;

    public static void main(String[] args) {
        int[] list2 = addOne(list, list.length-1);
        for (int i : list2) {
            System.out.print(i+" ");
        }
    }
    public static int[] addOne(int[] list, int tag) {
        if(list[0] == 9 && tag == 0) {
            int[] newlist = new int[length+1];
            newlist[0] = 1;
            return newlist;
        }
        if(list[tag] == 9) {
            list[tag] = 0;
            list = addOne(list, tag-1);
        } else {
            list[tag]++;
            return list;
        }
        return list;
    }
}
